<!-- 
* 结果页面 
* 2019年5月16日17:06:10
* penglei
* -->
<template>
    <view class="content">
		<scroll-view scroll-y="true">
			<m-res :listData="getList" @click="toPay" :bottonText="btext" :nopay="nopay" :m23lock="m23lock" :m32lock="m32lock" :m33lock="m33lock" @share='share'></m-res>
			<!-- <label class="concat">联系人工客服：领取您的实体卡。</label> -->
			<mBtnCs class="_lbtn" @click="tapY" text="咨询占卜师"  showImg='1' isconcat='0' />
			<mBtnCs class="_lbtn" @click="tapY1" text="人工客服"/>
		</scroll-view>
		<cmd-bottom-nav @click="tapNav"  border-color="#BC1BBE" background-color="#BC1BBE" font-color="#fff" active-font-color="#fff"  current="1"></cmd-bottom-nav>
    </view>
</template>

<script>
	import cmdBottomNav from "@/components/cmd-bottom-nav/cmd-bottom-nav.vue"
	import mbtn from "@/components/m-btn-type/m-btn.vue"
	import mBtnCs from '@/components/m-btn/m-btn-cs-zx.vue'
	import mRes from '@/components/m-res/m-res.vue'
	import comm from '../../common/helpers.js'
	import util from '../../static/js/util.js'
    export default {
		components:{mbtn,cmdBottomNav,mBtnCs,mRes},
		data(){
			return{
				text:'请从1-10里选择一个数字',
				middleTitle:'过去的状况',
				middlePage:'3/3',
				middleTost:'摒弃杂念选择一个数字',
				cardList:[
					{
						defaultCard:'../../static/img/card_def_one.png',
						activeCard:'../../static/img/card_act_one.png'
					},{
						defaultCard:'../../static/img/card_def_two.png',
						activeCard:'../../static/img/card_act_two.png'
					},{
						defaultCard:'../../static/img/card_def_three.png',
						activeCard:'../../static/img/card_act_three.png'
					},{
						defaultCard:'../../static/img/card_def_four.png',
						activeCard:'../../static/img/card_act_four.png'
					},{
						defaultCard:'../../static/img/card_def_five.png',
						activeCard:'../../static/img/card_act_five.png'
					},{
						defaultCard:'../../static/img/card_def_six.png',
						activeCard:'../../static/img/card_act_six.png'
					},{
						defaultCard:'../../static/img/card_def_seven.png',
						activeCard:'../../static/img/card_act_seven.png'
					},{
						defaultCard:'../../static/img/card_def_et.png',
						activeCard:'../../static/img/card_act_et.png'
					},{
						defaultCard:'../../static/img/card_def_nin.png',
						activeCard:'../../static/img/card_act_nin.png'
					},{
						defaultCard:'../../static/img/card_def_ten.png',
						activeCard:'../../static/img/card_act_ten.png'
					}
				],
				//最后结果数组容器
				listIt:[],
				resList:[],
				resStr:'',
				statu:0,
				oid:'',
				uec:[],
				m23lock:0,
				m32lock:0,
				m33lock:0,
				changeItem:'',
				where:[],
				isnext:false,
				brand:'',
				nopay:true,
				btext:'购买显示全部内容'
			}
		},
        onLoad(event) {
			// this.brand = uni.getStorageSync('brand')
			// if(this.brand == 'devtools'){
			// 	this.nopay = false
			// 	this.btext = 'IOS系统关闭支付功能，请联系客服'
			// }
			uni.setStorageSync('m32lock', 1);
			uni.setStorageSync('m33lock', 1);
			uni.setStorageSync('m23lock', 1);
			//登录获取openid
			comm.login()
			
			let that = this
			//过去、现在、未来数组容器
			let rel = Array();
			that.getOne(rel)
        },
		onShow() {
			let re = uni.getStorageSync('m23lock')
			this.m23lock = re
			re = uni.getStorageSync('m32lock')
			this.m32lock = re
			re = uni.getStorageSync('m33lock')
			this.m33lock = re
		},
		methods:{
			getThree(_rel){
				let that = this
				let res = uni.getStorageSync('3')
				_rel = res
				that.where[0] = _rel
				that.where[1] =  uni.getStorageSync('type')
				//调用方法
				that.getArr(that.where,"未来",3)
			},
			getTwo(_rel){
				let that = this
				let res = uni.getStorageSync('2')
				_rel = res
				that.where[0] =_rel
				that.where[1] =  uni.getStorageSync('type')
				//调用方法
				that.getArr(that.where,"现在",2)
				if(this.isnext=true){
					this.getThree(_rel)
				}
			},
			getOne(_rel){
				let that = this
				let res = uni.getStorageSync('1')
				_rel = res
				that.where[0] = _rel
				that.where[1] = uni.getStorageSync('type')
				//调用方法
				that.getArr(that.where,"过去",1)
				if(this.isnext=true){
					this.getTwo(_rel)
				}
				
			},
			tapNav(e){
				let that = this
				let path = e.item.pagePath
				uni.switchTab({
					url:path,
					success: (res) => {
					},
					complete: (com) => {
					}
				})
			},
			getArr(where,title,group){
				this.isnext=false
				let that = this
				let islock_two=0,islock_three=0
				let date = new Date()
				// 判断卡牌组
				/**
				 * islock_two：0 需要支付    1 不需要支付
				 * islock_three：0 需要支付    1 不需要支付
				 */
				if(group ==1){
						islock_two = 1
						islock_three = 1
				}
				//年
				var Y =
				date.getFullYear();
				//月
				var M = (date.getMonth()
				+ 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
				//日
				var D = date.getDate()
				< 10 ? '0' + date.getDate() :
				date.getDate();
				/**
				 * 进行数据请求，然后封装
				 */
				uni.request({
					url: comm.websiteUrl +'?s=v1/getgroup/',
					method: 'POST',
					data: {
						'gp':where[0],
						'tid':where[1],
						'mid':uni.getStorageSync('openid'),
						'r':'r'+group,
						'val':where[0],
						'date':Y+'-'+M+'-'+D
					},
					success: res => {
						// console.log(res)
						if(group ==2){
							islock_two = 1
							// if(res.data.count>=1){
							// 	that.m23lock = res.data.r[0].r2_model2_pay
							// 	islock_three = res.data.r[0].r2_model2_pay
							// }else{
								islock_three = 0
							// }
						}else if(group == 3){
							// if(res.data.count>=1){
								// that.m32lock = res.data.r[0].r3_model1_pay
								// that.m33lock = res.data.r[0].r3_model2_pay
								// islock_two = res.data.r[0].r3_model1_pay
								// islock_three = res.data.r[0].r3_model2_pay
							// }else{
								islock_two = 0
								islock_three = 0
							// }
						}
						// 组装数据
						let arr = {
							'title':title + '',
							'content':res.data.data.content,
							'descript':res.data.data.descript,
							'card_descript':res.data.data.card_description,
							'numArr':res.data.data.narr,
							'ititle':title+'',
							'islock_two':islock_two,
							'islock_three':islock_three,
							'thumb':res.data.data.image,
							'group':group
						}
						// 装填数据
						this.resList.push(arr)
						that.isnext=true
					},
					fail: () => {},
					complete: () => {}
				});
			}
			,
			compare(property){
				return function(a,b){
					var value1 = a[property];
					var value2 = b[property];
					return value1 - value2;
				}
			},
			/**
			 * @param {Object} _url
			 * @param {Object} _method
			 * @param {Object} _data
			 * @param {Object} _list  接收数据的数组
			 */
			publicResult:function(_url,_method,_data){
				let that = this
				uni.request({
					url: _url,
					method: _method,
					data:_data,
					success: res => {
						that.uec = res.data
						// console.log("res.data----uec")
						// console.log(that.uec)
					},
					fail: () => {},
					complete: () => {}
				});
			},
			toPay(e){
				let gdata = uni.getStorageSync('globalData').data
				// console.log(gdata)
				//先生成订单，然后返回订单信息，如果订单创建成功，跳转支付页面
				// 生成订单
				uni.request({
					url: comm.websiteUrl+'?s=v1/generatorder/',
					method: 'POST',
					data: {
						//代表占卜中小分类，比如“爱情”
						'rule':e.rule,
						// 代表所属分类
						'id':e.id,
						// 代表用户openid
						'mid':gdata.openid,
						//代表数字组合
						'goods_id':e.goods_id
					},
					success: res => {
						/**
						 * order_no：订单号
						 * mid：用户openid
						 * rule：订单类型及标题
						 * mo：所属小模块
						 * rmod：所属大模块
						 */
						if(res.data.code == 200){
							uni.navigateTo({
								url:'/pages/user/user_pay?order_no='+res.data.data.order_no+'&mid='+gdata.openid+'&rule='+e.rule+'&mo='+e.mo+'&rmod='+e.rmod+'&group='+e.goods_id,
								success: (res) => {
								}
							})
						}else{
							uni.showModal({
								title:'警告',
								content:'订单创建失败!!!',
								showCancel:false,
								success:function(res){
									// uni.switchTab({
									// 	url:'/pages/user/user'
									// })
								}
							})
							
						}
					},
					fail: () => {
					},
					complete: () => {}
				});
			},
			tapY(){
				util.navTo('/pages/help/counselor')
			},
			tapY1(){
				util.navTo('/pages/make/make')
			},
			// login(){
			// 	//如果未授权，进行授权，并且判断用户是否存在数据库，不存在则提示授权
			// 	uni.login({
			// 		provider: 'weixin',
			// 		success: res => {
			// 			// console.log('进入登录')
			// 			// console.log(res)
			// 			if (res.code) { 
			// 				uni.request({
			// 					url: comm.websiteUrl + '?s=v1/getuseropenid/',
			// 					method: 'POST',
			// 					data: {
			// 						'appid': comm.appId,
			// 						'appsecret': comm.appSecret,
			// 						'code': res.code
			// 					},
			// 					success: res => {
			// 						// console.log('获取openid')
			// 						this.globalData = res
			// 						uni.setStorageSync('globalData',res)
			// 					},
			// 					fail: () => {},
			// 					complete: () => {}
			// 				});
			// 			} else {
			// 				//用户按了拒绝按钮
			// 				uni.showModal({
			// 					title: '警告',
			// 					content: '授权失败，请重新授权!!!',
			// 					success: function(res) {}
			// 				})
			// 			}
			// 		},
			// 		fail: () => {},
			// 		complete: () => {
			// 	
			// 		}
			// 	});
			// }
			share(e){
				comm.downLoadHb(e,'/pages/share/share')
			}
		},
		computed:{
			getList(){
				this.resList.sort(this.compare('group'))
				this.listIt.push(this.resList)
				return this.listIt
			}
		}
    }
</script>

<style lang="scss">
	.content{
		padding: 0upx;
		width: 100%;
		height:100%;
		position: absolute;
		background-image: url('https://zhanbu.nomeis.cn/upload/page_resource/bg3.png');
		background-size: 100% 100%;
		
		scroll-view{
			height:85%;
			position:absolute;
			display:inline-block;
			background-image: url('https://zhanbu.nomeis.cn/upload/page_resource/bg3.png');
			background-size: 100% 100%;
			
			
			.concat{
				width:100%;
				display:flex;
				justify-content:center;
				color:white;
				font-size:11pt;
			}
		}
		
		._label_top{
			display:flex;
			width:100%;
			top:25upx;
			height:auto;
			position:relative;
			justify-content:center;

			._btn_top{
				height:185upx;
				width: 50%;
			}
			
			._lab_top{
				z-index:3;
				color:white;
				width:30%;
				text-align:center;
				justify-content:center;
				align-items:center;
				position:absolute;
				display:flex;
				margin:auto;
				height:100%;
			}
		}
		
		._bg_middle{
			width:100%;
			height:20%;
			position:absolute;
			z-index:7;
			margin:auto;
			justify-content:center;
			vertical-align:middle;
			align-items:center;
			display:flex;
			margin-top:125rpx;
			color: white;
			
			._middle_title{
				font-size:13pt;
				width:100%;
				position:absolute;
				margin-top:1rpx;
				text-align:center;
			}
			._middle_page{
				width:100%;
				position:absolute;
				font-size:9pt;
				margin-top:40rpx;
				text-align:center;
			}
			._middle_tost{
				width:100%;
				position:absolute;
				font-size:8pt;
				margin-top:80rpx;
				text-align:center;
				display:inline-block;
			}
			
			m-card{
				width:100%;
			}
		}
		
		._next{
			width:50%;
			margin:auto;
			margin-top:105%;
			position:relative;
			
			._tost{
				color:white;
				font-size:8pt;
				text-align:center;
				position:relative;
				display:flex;
				margin-top:25upx;
			}
		}
	}
</style>
